package com.yuhao.init.scheduled;

import com.yuhao.init.constant.FileConstant;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Objects;

/**
 * @Author: yuhao
 * @Date: 2024/5/7 16:29
 */

@Component
@EnableScheduling
public class ScheduledTask {
    @Scheduled(cron = "0 0 0 * * ?")
    public void timedDeleteImg(){
        File file = new File(FileConstant.TEMP_FILE_PATH);
        File[] files = file.listFiles();
        for (int i = 0; i < Objects.requireNonNull(files).length; i++) {
            boolean delete = files[i].delete();
            if (delete){
                System.out.println(files[i].getName()+"删除成功");
            }else {
                System.out.println(files[i].getName()+"删除失败");
            }
        }

    }
}
